<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Ddb::Userstamp::Stampable::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Ddb::Userstamp::Stampable::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/lib/stampable_rb.html">
                lib/stampable.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000005">stampable</a>&nbsp;&nbsp;
      <a href="#M000006">without_stamps</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">stampable</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This method is automatically called on for all classes that inherit from
ActiveRecord, but if you need to customize how the plug-in functions, this
is the method to use. Here&#8216;s an example:
</p>
<pre>
  class Post &lt; ActiveRecord::Base
    stampable :stamper_class_name =&gt; :person,
              :creator_attribute  =&gt; :create_user,
              :updater_attribute  =&gt; :update_user,
              :deleter_attribute  =&gt; :delete_user
  end
</pre>
<p>
The method will automatically setup all the associations, and create
<tt>before_save</tt> and <tt>before_create</tt> filters for doing the
stamping.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
    <span class="ruby-comment cmt"># File lib/stampable.rb, line 68</span>
68:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stampable</span>(<span class="ruby-identifier">options</span> = {})
69:           <span class="ruby-identifier">defaults</span>  = {
70:                         <span class="ruby-identifier">:stamper_class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:user</span>,
71:                         <span class="ruby-identifier">:creator_attribute</span>  =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Ddb</span><span class="ruby-operator">::</span><span class="ruby-constant">Userstamp</span>.<span class="ruby-identifier">compatibility_mode</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">created_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:creator_id</span>,
72:                         <span class="ruby-identifier">:updater_attribute</span>  =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Ddb</span><span class="ruby-operator">::</span><span class="ruby-constant">Userstamp</span>.<span class="ruby-identifier">compatibility_mode</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">updated_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:updater_id</span>,
73:                         <span class="ruby-identifier">:deleter_attribute</span>  =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Ddb</span><span class="ruby-operator">::</span><span class="ruby-constant">Userstamp</span>.<span class="ruby-identifier">compatibility_mode</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">deleted_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:deleter_id</span>
74:                       }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
75: 
76:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:stamper_class_name</span>].<span class="ruby-identifier">to_sym</span>
77:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">creator_attribute</span>  = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:creator_attribute</span>].<span class="ruby-identifier">to_sym</span>
78:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">updater_attribute</span>  = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:updater_attribute</span>].<span class="ruby-identifier">to_sym</span>
79:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">deleter_attribute</span>  = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:deleter_attribute</span>].<span class="ruby-identifier">to_sym</span>
80: 
81:           <span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
82:             <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:creator</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">singularize</span>.<span class="ruby-identifier">camelize</span>,
83:                                  <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">creator_attribute</span>
84:                                  
85:             <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:updater</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">singularize</span>.<span class="ruby-identifier">camelize</span>,
86:                                  <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">updater_attribute</span>
87:                                  
88:             <span class="ruby-identifier">before_save</span>     <span class="ruby-identifier">:set_updater_attribute</span>
89:             <span class="ruby-identifier">before_create</span>   <span class="ruby-identifier">:set_creator_attribute</span>
90:                                  
91:             <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-constant">Caboose</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Paranoid</span>)
92:               <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:deleter</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span>,
93:                                    <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">deleter_attribute</span>
94:               <span class="ruby-identifier">before_destroy</span>  <span class="ruby-identifier">:set_deleter_attribute</span>
95:             <span class="ruby-keyword kw">end</span>
96:           <span class="ruby-keyword kw">end</span>
97:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000006" class="method-detail">
        <a name="M000006"></a>

        <div class="method-heading">
          <a href="#M000006" class="method-signature">
          <span class="method-name">without_stamps</span><span class="method-args">() {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Temporarily allows you to turn stamping off. For example:
</p>
<pre>
  Post.without_stamps do
    post = Post.find(params[:id])
    post.update_attributes(params[:post])
    post.save
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000006-source">
<pre>
     <span class="ruby-comment cmt"># File lib/stampable.rb, line 106</span>
106:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_stamps</span>
107:           <span class="ruby-identifier">original_value</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span>
108:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span> = <span class="ruby-keyword kw">false</span>
109:           <span class="ruby-keyword kw">yield</span>
110:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span> = <span class="ruby-identifier">original_value</span>
111:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>